package com.sf.fy.uav.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sf.fy.uav.common.request.operate.CouponIntroductionReq;
import com.sf.fy.uav.common.response.operational.*;
import com.sf.fy.uav.common.response.order.CouponPriceResponse;
import com.sf.fy.uav.common.utils.Rs;
import com.sf.fy.uav.entity.UserCoupon;
import com.sf.fy.uav.mapper.UserCouponMapper;
import com.sf.fy.uav.service.IUserCouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author LTQ
 * @since 2023-10-07
 */
@RestController
@RequestMapping("/sys/user-coupon/")
public class UserCouponRest {

    @Autowired
    private IUserCouponService iUserCouponService;

    @Autowired
    private UserCouponMapper userCouponMapper;

    public UserCouponRsResponse getAvailableCoupons(Integer page, Integer size, BigDecimal price, Integer isMustStart) {
        return iUserCouponService.getAvailableCoupons(page, size, price, isMustStart);
    }

    public UserCouponRsResponse getUnavailableCoupons(Integer page, Integer size, BigDecimal price) {
        return iUserCouponService.getUnavailableCoupons(page, size, price);
    }

    public CouponPriceResponse calculatePrice(BigDecimal price, String id) {
        return iUserCouponService.calculatePrice(price, id);
    }

    public UserCoupon getEffectiveCoupon(BigDecimal price, String id) {
        return iUserCouponService.getEffectiveCoupon(price, id);
    }

    public ExpireOrUsedUserRsCouponResponse getExpireOrUsedCoupons(Integer page, Integer size) {
        return iUserCouponService.getExpireOrUsedCoupons(page, size);
    }


    public Rs<CouponIntroductionResult> introduction(CouponIntroductionReq couponIntroductionReq) {
        return iUserCouponService.introduction(couponIntroductionReq);
    }

    public List<UserCoupon> getByCouponIdsAndUserId(List<String> couponIds, String userId) {
        QueryWrapper<UserCoupon> userCouponQueryWrapper = new QueryWrapper<>();
        userCouponQueryWrapper.lambda().in(UserCoupon::getCouponId, couponIds).eq(UserCoupon::getUserId, userId);
        return userCouponMapper.selectList(userCouponQueryWrapper);
    }

}
